package com.firefly.netty.demo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.firefly.util.utils.JsonUtil;
import lombok.Data;

import java.util.Map;

/**
 * @description:
 * @author: lzg(萤火科技 ： 854378082 @ qq.com)
 * @date: 2022/9/15
 **/
@Data
public class DataFrame {
    // 最大512
    public String Len = "500";
    public String Cmd;
    public String SN;
    public String DataTime;
    // FFF 不校验
    public String CRC = "FFFF";
    public String Addr;
    public Map<String,String> DataValue;

    @Override
    public String toString(){
        String dataStr = "{}";
        if (DataValue != null){
            try {
                dataStr = JsonUtil.obj2Str(DataValue);
            } catch (JsonProcessingException e) {
                throw new RuntimeException(e);
            }
        }
        String resultStr = "{'Len':'" + Len + "','Cmd':'" + Cmd + "','SN':'" + SN + "','DataTime':'" + DataTime + "','CRC':'" + CRC + "','Addr':'" + Addr + "','DataValue':" + dataStr + "}";
        resultStr = resultStr.replaceAll("\"","\'");
        return resultStr;
    }
}
